package enableenum

import (
	"yunj/pkg/yunj/core/enum"
)

// 定义启用常量
const (

	// 开启
	ON uint8 = 1

	// 关闭
	OFF uint8 = 0
)

// 启用
// 实现EnumInerface接口
type Enable struct {
	enum.Enum[uint8]
}

// pageopentype.uint8.GetDescMap()
func (e *Enable) AllConstAttrs() map[uint8]map[string]any {
	return map[uint8]map[string]any{
		ON: {
			"desc": "开启",
			"sort": 1,
		},
		OFF: {
			"desc": "关闭",
			"sort": 2,
		},
	}
}

// instanceCache 存储已经创建的实例
var instanceCache = make(map[uint8]*Enable)

// 根据value获取枚举
func ByValue(value uint8) *Enable {
	if instance, exists := instanceCache[value]; exists {
		return instance
	}
	e := &Enable{}
	enum.SetEnumInstance(&e.Enum, e, value)
	instanceCache[value] = e
	return e
}

var Enum *Enable = func() *Enable {
	e := &Enable{}
	enum.SetEnumInstance(&e.Enum, e)
	return e
}()
